<?php

namespace App\Logic\Auth\Form;

use App\Core\BaseListForm;
use App\Model\Auth\RoleModel;
use App\Util\UserIdentityHelper;

class RoleListForm extends BaseListForm{

    public function lists(){
        $where = [];

        $model = RoleModel::makeQueryModel($where, [], $this->getPagination());

        $model->order( 'id', 'ASC');

        $model->field(['id','name','state','is_action','type']);

        $modelResult = $model->all();

        $list = [];
        foreach($modelResult as $v){
            $item              = $v->toArray();
            $item['type_name'] = RoleModel::getTypeDict($v->type);
            $list[]            = $item;
        }

        $total = $model->lastQueryResult()->getTotalCount();

        $pagination = $this->getPagination();
        $pagination['total_count'] = $total;

        $result = [
            'list'       => $list,
            'pagination' => $pagination
        ];

        return $this->success($result);
    }

}